package com.frame.model.third.res;

import com.frame.para.ParametersUtil;
import com.frame.wechat.RandomStringGenerator;
import com.frame.wechat.WechatUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("JsApiData")
public class ResJsApiDataVO {
    /**
     * 随机字符串
     */
	@ApiModelProperty("随机字符串")
    private String noncestr;

    /**
     * 时间戳
     */
	@ApiModelProperty("时间戳")
    private String timestamp;


    /**
     * 当前页面的URL
     */
    @ApiModelProperty("当前页面的URL")
    private String url;


    /**
     * sapi_ticketO
     */
	@ApiModelProperty("jsapi_ticket")
    private String jsapi_ticket;

	@ApiModelProperty(value = "appid")
    private String appid;

    /**
     * 签名
     */
	@ApiModelProperty("签名")
    private String sign;

    public ResJsApiDataVO(String url,String jsapiTicket){
        this.url = url;
        this.jsapi_ticket=jsapiTicket;
        this.timestamp=String.valueOf(System.currentTimeMillis()).substring(0,10);
        //随机字符串，不长于32 位
        this.noncestr=RandomStringGenerator.getRandomStringByLength(32);
        //根据API给的签名规则进行签名
        String sign = WechatUtil.getSignToJS(ParametersUtil.objcetToMap(this));
        //把签名数据设置到Sign这个属性中
        this.sign=sign;
    }



}
